package com.mobile.paperazi.view;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.View;

import com.mobile.paperazi.data.Content;
import com.mobile.paperazi.data.Page;
import com.mobile.paperazi.data.Tag;

public class CustomView extends View {

	Page page;
	Paint paint;
	private HashMap<RectF, List<Content>> contentMap;
	public CustomView(Context context, Page page) {
		super(context);
		this.page = page;
		this.paint = new Paint();
		setContentMap(new HashMap<RectF, List<Content>>());
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(2);
		paint.setColor(Color.GREEN);
		List<Tag> taglist = page.getTagsList();
		float height = page.getHeight();
		float width = page.getWidth();
		float x, y, w, h;
		for (Tag tag : taglist) {
			x = tag.getStartX() * width / page.getPaperWidth();
			y = tag.getStartY() * height / page.getPaperHeight();
			w = tag.getWidth() * width / page.getPaperWidth();
			h = tag.getHeight() * height / page.getPaperHeight();
			canvas.drawRect(x, y, x + w, y + h, paint);
			RectF rec = new RectF(x, y, x + w, y + h);
			getContentMap().put(rec, tag.getContentList());
		}
	}

	public HashMap<RectF, List<Content>> getContentMap() {
		return contentMap;
	}

	public void setContentMap(HashMap<RectF, List<Content>> contentMap) {
		this.contentMap = contentMap;
	}

}